package _base0to1;

/**
 * 860. 柠檬水找零
 */
public class No860 {
    public boolean lemonadeChange(int[] bills) {
        int[] surplus = new int[2];
        for (int bill : bills) {
            switch (bill) {
                case 5:
                    surplus[0]++;
                    break;
                case 10:
                    if (surplus[0] > 0) {
                        surplus[0]--;
                        surplus[1]++;
                    } else return false;
                    break;
                case 20:
                    if (surplus[1] > 0) {
                        if (surplus[0] > 0) {
                            surplus[0]--;
                            surplus[1]--;
                        } else return false;
                    } else if (surplus[0] > 2) {
                        surplus[0] -= 3;
                    } else return false;
            }
        }
        return true;
    }
}
